home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / CarbonizedMenus / source / FontInfo.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  2.9 KB  |  116 lines  |  [TEXT/CWIE]

  1. /****************************************************************************************
  2.     FontInfo.cp
  3.     
  4.     Copyright © 1999 Red Shed Software. All rights reserved.
  5.     by Jonathan 'Wolf' Rentzsch (jon@redshed.net)
  6.     
  7.     Commenter    Date                Comment
  8.     ---------    -----------------    -----------------------------------------------------
  9.     wolf        Thu, Jun 24, 1999    Created.
  10.     
  11.     ************************************************************************************/
  12.  
  13. #include    "FontInfo.h"
  14.  
  15. UInt16    gMaxFontHeight = 0;
  16. UInt16    gMaxFontWidth = 0;
  17.  
  18. /****************************************************************************************
  19.     Commenter    Date                Comment
  20.     ---------    -----------------    -----------------------------------------------------
  21.     wolf        Thu, Jun 24, 1999    Created.
  22.     
  23.     ************************************************************************************/
  24.  
  25.     UInt16
  26. GetMaxFontHeight(
  27.     ConstStr255Param    fontName,
  28.     short                size,
  29.     StyleParameter        face )
  30. {
  31.     GrafPtr        port;
  32.                 GetPort( &port );
  33.     short        oldFont = port->txFont;
  34.     short        oldSize = port->txSize;
  35.     StyleField    oldFace = port->txFace;
  36.     
  37.     short        fontID;
  38.                 GetFNum( fontName, &fontID );
  39.     
  40.     TextFont( fontID );
  41.     TextSize( size );
  42.     TextFace( face );
  43.                 
  44.     FontInfo    fInfo;
  45.                 GetFontInfo( &fInfo );
  46.     
  47.     TextFont( oldFont );
  48.     TextSize( oldSize );
  49.     TextFace( oldFace );
  50.     
  51.     gMaxFontHeight = fInfo.ascent + fInfo.descent;
  52.     return( gMaxFontHeight );
  53. }
  54.  
  55. /****************************************************************************************
  56.     Commenter    Date                Comment
  57.     ---------    -----------------    -----------------------------------------------------
  58.     wolf        Thu, Jun 24, 1999    Created.
  59.     
  60.     ************************************************************************************/
  61.  
  62.     UInt16
  63. GetMaxFontWidth(
  64.     ConstStr255Param    fontName,
  65.     short                size,
  66.     StyleParameter        face )
  67. {
  68.     GrafPtr        port;
  69.                 GetPort( &port );
  70.     short        oldFont = port->txFont;
  71.     short        oldSize = port->txSize;
  72.     StyleField    oldFace = port->txFace;
  73.     
  74.     short        fontID;
  75.                 GetFNum( fontName, &fontID );
  76.     
  77.     TextFont( fontID );
  78.     TextSize( size );
  79.     TextFace( face );
  80.                 
  81.     FontInfo    fInfo;
  82.                 GetFontInfo( &fInfo );
  83.     
  84.     TextFont( oldFont );
  85.     TextSize( oldSize );
  86.     TextFace( oldFace );
  87.     
  88.     gMaxFontWidth = fInfo.widMax;
  89.     return( gMaxFontWidth );
  90. }
  91.  
  92. /****************************************************************************************
  93.     Commenter    Date                Comment
  94.     ---------    -----------------    -----------------------------------------------------
  95.     wolf        Thu, Jun 24, 1999    Created.
  96.     
  97.     ************************************************************************************/
  98.  
  99.     UInt16
  100. GetCachedMaxFontHeight()
  101. {
  102.     return( gMaxFontHeight );
  103. }
  104.  
  105. /****************************************************************************************
  106.     Commenter    Date                Comment
  107.     ---------    -----------------    -----------------------------------------------------
  108.     wolf        Thu, Jun 24, 1999    Created.
  109.     
  110.     ************************************************************************************/
  111.  
  112.     UInt16
  113. GetCachedMaxFontWidth()
  114. {
  115.     return( gMaxFontWidth );
  116. }